library ScriptItemSpawn requires TextSystem, NOTDAMisc, GlobalVariables

	function GetRandomItemLocation takes nothing returns location
		 local location l = GetRandomLocInRect(udg_ItemRectangle)
		 if (IsTerrainPathableBJ(l, PATHING_TYPE_WALKABILITY) == true )then
			 return l
		 else
			 call RemoveLocation(l)
			 set l = null
			 return GetRandomItemLocation()
		 endif
	endfunction

	function ItemSpawnN takes integer itemid, integer count returns nothing
		local integer i=1
		local location l
		loop
			exitwhen i>count
			call TriggerSleepAction(0.25) 

			set l = GetRandomItemLocation() 
			call DestroyEffect(AddSpecialEffectLocBJ( l, "Units\\Demon\\Infernal\\InfernalBirth.mdl"))  
			call CreateItemLoc( itemid,l) 
			// call UnitDamagePointLoc( udg_Residence41, 0, 250, l, 100, ATTACK_TYPE_SIEGE, DAMAGE_TYPE_NORMAL)    
			call RemoveLocation(l)
			set i=i+1
		endloop
		set l = null
	endfunction


	function C130Wave15 takes nothing returns nothing
		local integer dropfactor = 0
		if udg_SquadXP>120000 then
			set dropfactor = 8
		elseif udg_SquadXP>60000 then
			set dropfactor = 5
		endif
		call GeneralText(5.0, "|cffcd950cBattalion|r : C-130s have airdropped more equipment to your region. You will need those Nano Body Armors!" )
		if udg_Players>=5 then
			call ItemSpawnN('shas',20-dropfactor) //Ammunition Box
		else
			call ItemSpawnN('shas',16-dropfactor) //Ammunition Box
		endif
		call ItemSpawnN('phea',4) //Fibrin Bandage
		call ItemSpawnN('I00J',2) //Anti-Venom
		call ItemSpawnN('I00E',4) //Claymore Case
		call ItemSpawnN('I00D',3) //Rifle Grenades
		call ItemSpawnN('I00M',4) //Road Flares
		call ItemSpawnN('I005',2) //Reactive Body Armor
		call ItemSpawnN('I00C',4) //Shotgun Shells
		call ItemSpawnN('I004',4) //Medkit
		call ItemSpawnN('I009',2) //RMS-12A Browning
		call ItemSpawnN('I000',1) //M240G
		call ItemSpawnN('I00B',2) //M-29
		call ItemSpawnN('I00O',1) //TX-1 Ammunition
		call ItemSpawnN('ckng',2) //U-238E Ammunition
		call ItemSpawnN('I00A',2) //Blastocyst Module
		call ItemSpawnN('I010',5) //Satchel
		call ItemSpawnN('I00Z',2+udg_InitialPlayers) //Nano Body Armor
		call debugmsg("Finished Dropping wave 15 Items")
	endfunction

	function C130Wave10 takes nothing returns nothing
		local integer dropfactor = 0
		if udg_SquadXP>150000 then
			set dropfactor = 5
		elseif udg_SquadXP>75000 then
			set dropfactor = 3
		endif
		call GeneralText(5.0, "|cffcd950cBattalion|r : C-130s have airdropped more equipment to your region." )
		if udg_Players>=5 then
			call ItemSpawnN('shas',12-dropfactor) //Ammunition Box
		else
			call ItemSpawnN('shas',8-dropfactor) //Ammunition Box
		endif
		if udg_Difficulty==5 then
			call ItemSpawnN('shas',5) //Ammunition Box
		endif
		call ItemSpawnN('I004',4) //Medkit
		call ItemSpawnN('phea',4) //Fibrin Bandage
		call ItemSpawnN('I00J',3) //Anti-Venom
		call ItemSpawnN('I00E',3) //Claymore Case
		call ItemSpawnN('I00D',3) //Rifle Grenades
		call ItemSpawnN('I00M',2) //Road Flares
		call ItemSpawnN('I005',2) //Reactive Body Armor
		call ItemSpawnN('I00C',10) //Shotgun Shells
		call ItemSpawnN('I00W',4) //Flare Gun
		call ItemSpawnN('I009',1) //RMS-12A Browning
		call ItemSpawnN('I00B',1) //XM-29
		call ItemSpawnN('I00I',3) //SMAW
		call ItemSpawnN('I000',1) //M240G
		call ItemSpawnN('I00G',1) //E-Cell
		call ItemSpawnN('I00A',1) //Blastocyst Module
		call ItemSpawnN('I00O',1) //TX-1 Ammunition
		call ItemSpawnN('I00U',2) //Det Cord
		call ItemSpawnN('I010',1) //Satchel
		//call ItemSpawnN('I013',1) //Hellfire Upgrade
		call debugmsg("Finished Dropping wave 10 Items")
	endfunction

	function C130Wave6 takes nothing returns nothing
		if udg_Players>=5 and udg_SquadXP<125000 then
			call ItemSpawnN('shas',6) //Ammunition Box
		else
			call ItemSpawnN('shas',4) //Ammunition Box
		endif
		if udg_Difficulty==5 then
			call ItemSpawnN('shas',5) //Ammunition Box
		endif
		call ItemSpawnN('ckng',3) //U-238E Ammunition
		call ItemSpawnN('I001',4) //Composite Personnel Armor
		call ItemSpawnN('I00G',1) //E-Cell
		call ItemSpawnN('I00A',1) //Blastocyst Module
		call ItemSpawnN('I00M',1) //Road Flares
		call ItemSpawnN('I00I',1) //SMAW
		call ItemSpawnN('I00N',1) //M320
		call ItemSpawnN('I00U',2) //Det Cord
		call ItemSpawnN('I00W',2) //Flare Gun
		call ItemSpawnN('I010',1) //Thermal Detonator
		call ItemSpawnN('I011',1) //Transceiver
		//call ItemSpawnN('I013',1) //Hellfire Upgrade
		call debugmsg("Finished Dropping wave 6 Items")
	endfunction

	function C130Wave1 takes nothing returns nothing
		if udg_SquadXP<60000 then
			call ItemSpawnN('shas',4) //Ammunition Box
		endif
		call PolledWait(0.5)
		if udg_Players>=9 then
			call ItemSpawnN('shas',9) //Ammunition Box
		elseif udg_Players>=5 then
			call ItemSpawnN('shas',7) //Ammunition Box
		else
			call ItemSpawnN('shas',5) //Ammunition Box
		endif
		call PolledWait(0.5)
		call ItemSpawnN('I008',4) //RMS-8 Benelli
		call ItemSpawnN('I00D',6) //Rifle Grenades
		call ItemSpawnN('I00M',3) //Road Flares
		call PolledWait(0.5)
		call ItemSpawnN('phea',5) //Fibrin Bandage
		call ItemSpawnN('phea',5) //Fibrin Bandage
		call ItemSpawnN('I00C',5) //Shotgun Shells
		call ItemSpawnN('I00C',5) //Shotgun Shells
		call ItemSpawnN('I00J',4) //Anti-Venom
		call ItemSpawnN('I00J',4) //Anti-Venom
		call ItemSpawnN('I002',4) //AP Ammo
		call PolledWait(0.5)
		call ItemSpawnN('rde1',5) //Kevlar Armor
		call ItemSpawnN('I00E',6) //Claymore Case
		call ItemSpawnN('I00F',5) //Chain Explosive Case
		call ItemSpawnN('I00F',5) //Chain Explosive Case
		call ItemSpawnN('I004',5) //Medkit
		if udg_SquadXP<60000 then
			call ItemSpawnN('I004',5) //Medkit
		endif
		call ItemSpawnN('I00X',1) //Pancor Jackhammer
		call ItemSpawnN('I00B',1) //XM-29
		call ItemSpawnN('I000',1) //M240G
		call PolledWait(0.5)
		call ItemSpawnN('I003',2) //Arclite Hecate
		call ItemSpawnN('I007',1) //SAM-R
		call ItemSpawnN('I00G',1) //E-Cell
		call ItemSpawnN('I00I',1) //SMAW
		call ItemSpawnN('I00A',1) //Blastocyst Module
		call ItemSpawnN('I00N',4) //M320
		call ItemSpawnN('I00U',2) //Det Cord
		call ItemSpawnN('I009',1) //RMS-12A Browning
		call ItemSpawnN('I010',1) //Satchel
		call ItemSpawnN('I011',1) //Transceiver
		call ItemSpawnN('I015',1) //Freedom
		call ItemSpawnN('I016',1) //Justice
		call debugmsg("Finished Dropping wave 1 Items")
	endfunction

endlibrary